<template>
    <div class="all-comment">
        <div class="comment-card" v-for="(item,index) in allComment" :key="index">
            <div class="comment-head">
                <div class="avatar-box">
                    <img :src="item.headimgurl" alt="">
                </div>
                <div class="user-msg">
                    <div class="msg-detail">
                        <span>{{item.nickname}}</span>
                        <div class="stars-lv">
                            <div class="stars-box" v-for="(starItem, starIndex) in 5" :key="starIndex">
                                <img src="~assets/icons/star_orange.png" alt="" v-show="starIndex <= item.degree-1">
                                <img src="~assets/icons/star_empty.png" alt="" v-show="starIndex > item.degree-1">
                            </div>
                        </div>
                        <span>商城购买{{item.number}}次</span>
                    </div>
                    
                    <div class="head-date">
                        {{item.pay_time}}
                    </div>
                </div>
            </div>
            <div class="comment-content">
                <p>{{item.content}}</p>
            </div>
            <div class="comment-image">
                <img :src="item['image_url']" alt="">
            </div>
            <div class="label-box">
                <div class="product-label" v-for="(subItem,i) in item.norms" :key="i">
                    <span>{{subItem.name}}:</span>
                    <span>（{{subItem.attributes}}） </span>
                </div>
            </div>
            
        </div>
    </div>
</template>

<script>
export default {
    name:"allComment",
    data(){
        return {
            starNum:2,
            allComment:[]
        }
    },
    methods:{
        getAllComment(){
            let that = this;
            let id = that.$route.query.id;
            let token = localStorage.getItem('token');
            let loader = that.loading();
            that.$ajax(that, 'get', that.$api.showComment+id, null, token, function(res){
                if(res.data['error_code'] == 0){
                    that.allComment = res.data.msg;
                    that.transferUrl(that.allComment);
                    console.log(that.allComment);
                }
                loader.close();
            })
        }
    },
    mounted(){
        this.getAllComment();
        this.$store.state.tab = '用户说';
    },
    activated(){
        this.getAllComment();
        this.$store.state.tab = '用户说';
    }
}
</script>

<style lang='less'>
@rem:100rem;

.all-comment{
    margin-top: 88/@rem;
    padding-top: 10/@rem;
    .comment-card{
        width: 100%;
        background: #ffffff;
        border-bottom: 1px solid #f0f0f0;
        padding: 10/@rem 0;
        .comment-head{
            width: 100%;
            box-sizing: border-box;
            padding: 0 20/@rem;
            display: flex;
            align-items: center;
            .avatar-box{
                height: 80/@rem;
                width: 80/@rem;
                overflow: hidden;
                border-radius: 50%;
                display: flex;
                align-items: center;
                justify-content: center;
                img{
                    height: 80/@rem;
                }
            }
            .user-msg{
                display: flex;
                flex-direction: column;
                .msg-detail{
                    text-align: start;
                    margin-left: 20/@rem;
                    display: flex;
                    align-items: center;
                    span:nth-of-type(1){
                        font-size: 26/@rem;
                    }
                    span:nth-of-type(2){
                        font-size: 22/@rem;
                        color: #fd4141;
                        margin-left: 20/@rem
                    }
                    .stars-lv{
                        display: flex;
                        height: 26/@rem;
                        margin-left: 20/@rem;
                        align-items: center;
                        .stars-box{
                            height: 26/@rem;
                            width: 26/@rem;
                            margin-right: 6/@rem;
                            img{
                                height: 24/@rem;
                                width: 24/@rem;
                                vertical-align: top;
                            }
                        }
                    }
                }
                
                .head-date{
                    text-align: start;
                    margin-left: 20/@rem;
                    margin-top: 10/@rem;
                }
            }
        }
        .comment-content{
            padding-left: 120/@rem;
            margin-top: 20/@rem;
            text-align: start;
            font-size: 30/@rem;
            color: #333333;
        }
        .comment-image{
            margin-left: 120/@rem;
            text-align: start;
            margin-top: 20/@rem;
            img{
                height: 160/@rem;
            }
        }
        .label-box{
            display: flex;
            margin-top: 20/@rem;
            margin-left: 120/@rem;
        }
        .product-label{
            text-align: start;
            font-size: 24/@rem;
            color: #868686;
        }
    }
}
</style>
